package com.sky.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @BelongsProject: sky-take-out
 * @BelongsPackage: com.sky.config
 * @Author: XieMingHui
 * @CreateTime: 2023-11-16  20:41
 * @Description: mybatisPlus分页拦截器
 * @Version: 1.0
 */
@Configuration
public class MybatisPlusPageConfig  {

    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        // 1.初始化核心插件
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        // 2.添加分页插件,并设置SQL语句方言为MYSQL
        PaginationInnerInterceptor pageInterceptor = new PaginationInnerInterceptor(DbType.MYSQL);
        // 3.设置分页上限为1000条
        pageInterceptor.setMaxLimit(1000L);
        // 4.注册启用分页插件
        interceptor.addInnerInterceptor(pageInterceptor);
        // 5.将插件对象返回
        return interceptor;
    }
}
